package org.abacus.platform.data;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Map;

class FetchStatement implements Store {
	private final Statement stmt;
	private Store store;

	public FetchStatement(Statement stmt, String sql) {
		super();
		this.stmt = stmt;
		try {
			store = new FetchResultSet(this.stmt.executeQuery(sql));
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close();
		}
	}

	@Override
	public void open() {
		store.open();
	}

	@Override
	public List<Map<String, Object>> getStore() {
		return store.getStore();
	}

	@Override
	public List<Key> getKeys() {
		return store.getKeys();
	}

	@Override
	public void close() {
		store.close();
		try {
			if (null != stmt)
				stmt.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
